/*
========================================================================
 Name        : ExportContactsExportingContainerView.cpp
 Author      : 
 Copyright   : Your copyright notice
 Description : 
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <aknviewappui.h>
#include <eikmenub.h>
#include <avkon.hrh>
#include <barsread.h>
#include <stringloader.h>
#include <eiklabel.h>
#include <eikenv.h>
#include <gdi.h>
#include <eikgted.h>
#include <akncontext.h>
#include <akntitle.h>
#include <eikbtgpc.h>
#include <ExportContacts.rsg> 

#include "ExportContacts.hrh"
#include "ExportContactsExportingContainerView.h"
#include "ExportContactsListBox.hrh"
#include "ExportContactsSelectDirContainer.hrh"
#include "ExportContactsExportingContainer.hrh"
#include "ExportContactsExportingContainer.h"
#include "ContactEngine.h" 
#include "ExportContactsAppUi.h"

CExportContactsExportingContainerView::CExportContactsExportingContainerView()
{	 
	iExportContactsExportingContainer = NULL;	
	iContactEngine = NULL;	
}

 
CExportContactsExportingContainerView::~CExportContactsExportingContainerView()
{	 
	delete iExportContactsExportingContainer;
	iExportContactsExportingContainer = NULL;	
}

 
CExportContactsExportingContainerView* CExportContactsExportingContainerView::NewL()
{
	CExportContactsExportingContainerView* self = CExportContactsExportingContainerView::NewLC();
	CleanupStack::Pop( self );
	return self;
} 
 
CExportContactsExportingContainerView* CExportContactsExportingContainerView::NewLC()
{
	CExportContactsExportingContainerView* self = new ( ELeave ) CExportContactsExportingContainerView();
	CleanupStack::PushL( self );
	self->ConstructL();
	return self;
}
 
void CExportContactsExportingContainerView::ConstructL()
{	 
	BaseConstructL( R_EXPORT_CONTACTS_EXPORTING_CONTAINER_EXPORT_CONTACTS_EXPORTING_CONTAINER_VIEW_2 );	
}

 
TUid CExportContactsExportingContainerView::Id() const
{
	return TUid::Uid( EExportContactsExportingContainerViewId );
}

 
void CExportContactsExportingContainerView::HandleCommandL( TInt aCommand )
{ 
	TBool commandHandled = EFalse;
	switch ( aCommand )
	{	 
	    case EExportContactsExportingContainerViewHelp_MenuItemCommand:
		{
			AppUi()->HandleCommandL(EExportContactsListBoxViewHelp_MenuItemCommand);
		}
		break;
	    case EExportContactsExportingContainerViewAbout_MenuItemCommand:
		{
			AppUi()->HandleCommandL(EExportContactsListBoxViewAbout_MenuItemCommand);
		}
		break;
	    case EAknSoftkeyExit:
		{
			AppUi()->HandleCommandL( EEikCmdExit );
		}
		default:
		break;
	}		 
}


void CExportContactsExportingContainerView::DoActivateL( 
														const TVwsViewId&  aPrevViewId,
														TUid aCustomMessageId,
														const TDesC8& aCustomMessage )
{ 
	SetupStatusPaneL();				
	if ( iExportContactsExportingContainer == NULL )
	{
		iExportContactsExportingContainer = CreateContainerL();
		iExportContactsExportingContainer->SetMopParent( this );
		AppUi()->AddToStackL( *this, iExportContactsExportingContainer );
	} 
	CExportContactsAppUi* appUi = (CExportContactsAppUi*)AppUi();
	iExportContactsExportingContainer->SetExportFile(appUi->GetExportFile());	
	
	appUi->StartExporting();	
}

 
void CExportContactsExportingContainerView::DoDeactivate()
{ 
	CleanupStatusPane();
	
	if ( iExportContactsExportingContainer != NULL )
	{
		AppUi()->RemoveFromViewStack( *this, iExportContactsExportingContainer );
		delete iExportContactsExportingContainer;
		iExportContactsExportingContainer = NULL;
	}	
}

 
void CExportContactsExportingContainerView::HandleStatusPaneSizeChange()
{
	CAknView::HandleStatusPaneSizeChange();	 
	TVwsViewId view;
	AppUi()->GetActiveViewId( view );
	if ( view.iViewUid == Id() )
	{
		TInt result;
		TRAP( result, SetupStatusPaneL() );
	}		
}

 
void CExportContactsExportingContainerView::SetupStatusPaneL()
{	 
	TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
	CEikStatusPaneBase::TPaneCapabilities subPaneTitle = 
		StatusPane()->PaneCapabilities( titlePaneUid );
	if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
	{
		CAknTitlePane* title = static_cast< CAknTitlePane* >( 
			StatusPane()->ControlL( titlePaneUid ) );
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_EXPORT_CONTACTS_EXPORTING_CONTAINER_TITLE_RESOURCE_2 );
		title->SetFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
	}			
	  
	TUid contextPaneUid = TUid::Uid( EEikStatusPaneUidContext );
	CEikStatusPaneBase::TPaneCapabilities subPaneContext = 
			StatusPane()->PaneCapabilities( contextPaneUid );
	if ( subPaneContext.IsPresent() && subPaneContext.IsAppOwned() )
	{
		CAknContextPane* context1 = static_cast< CAknContextPane* > ( 
			StatusPane()->ControlL( contextPaneUid ) );
		TResourceReader reader;
		iCoeEnv->CreateResourceReaderLC( reader, R_EXPORT_CONTACTS_EXPORTING_CONTAINER_CONTEXT1_RESOURCE );
		context1->SetFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
	}			
}


void CExportContactsExportingContainerView::SetContactEngine(ContactEngine* aContactEngine)
{
	iContactEngine = aContactEngine;
}

void CExportContactsExportingContainerView::SetExportFile(const TDesC& aExportFile)
{
//	iExportContactsExportingContainer->SetExportFile(aExportFile);	
}

void CExportContactsExportingContainerView::CleanupStatusPane()
{
}

void CExportContactsExportingContainerView::ExportingNotify(const TInt aCurrentCount,const TInt aWholeCount)
{
	if(iExportContactsExportingContainer)
	{
		iExportContactsExportingContainer->ExportingNotify(aCurrentCount,aWholeCount);
	}
}
 
CExportContactsExportingContainer* CExportContactsExportingContainerView::CreateContainerL()
{
	return CExportContactsExportingContainer::NewL( ClientRect(), NULL, this );
} 
//end of file
